<?php
class Support extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->helper('url');
        if (file_exists('application/controllers/install.php'))
            redirect('install');
        $this->load->model('poll_model');
        $this->load->model('works_model');
        $this->load->model('category_model');

    }

    function index() {
        $pid = $this->input->get('pid');
        $id = $this->input->get('id');
        $data['query'] = $this->works_model->select();
        if (empty($data['query'])) { // if pid not existed, redirect
            $data['title'] = '出错啦';
            $data['words'] = '查询id错误';
            $this->load->view('templates/header', $data);
            $this->load->view('poster_admin/404', $data);
            $this->load->view('templates/footer', $data);
        } else {
            $ip = $_SERVER["REMOTE_ADDR"];
            if ($this->poll_model->insert($pid, $ip, $id)) {
                $data['title'] = '出错啦';
                $data['words'] = '对不起您已经投过票了，一个ip限制投票一次';
                $this->load->view('templates/header', $data);
                $this->load->view('poster_admin/404', $data);
                $this->load->view('templates/footer', $data);
            } else {
                redirect('detail?pid='.$pid, 'refresh');
            }
        }
    }
}